package com.winbaoxian.common.freemarker.functions;

import com.winbaoxian.common.freemarker.constant.TemplateMethodModelExMsg;
import com.winbaoxian.common.freemarker.utils.NameUtils;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.utility.DeepUnwrap;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @author dongxuanliang252
 * @date 2021-04-07 18:19:27
 */
public class HumpCaseFunction implements TemplateMethodModelEx {


    /**
     * 返回json
     * USAGE
     * camelCase("user_info")
     *
     * @return UserInfo
     */
    @Override
    public Object exec(List list) throws TemplateModelException {
        if (CollectionUtils.isEmpty(list)) {
            throw new TemplateModelException(TemplateMethodModelExMsg.MISSING_PARAMETERS);
        }
        String text = (String) DeepUnwrap.unwrap((TemplateModel) list.get(0));
        return NameUtils.INSTANCE.humpCase(text);
    }

}
